package com.mzl.lal4cloud.lxw4rf.service.contract.bean;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

/**
 * @author J_luo
 */
@Slf4j
public class HostConfig {

    public static final String API_DEFAULT_HOST_URL = "https://api.bestsign.cn";

    public static final String API_TEST_HOST_URL = "https://api.bestsign.info";


    @Getter
    @Setter
    protected volatile boolean useSandboxEnv = false;


    public HostConfig(){}

    public HostConfig(boolean useSandboxEnv){
        this.useSandboxEnv = useSandboxEnv;
    }

    public String getHost(){
        return useSandboxEnv ? API_TEST_HOST_URL : API_DEFAULT_HOST_URL;
    }

    /**
     * 组合地址
     *
     * @param hostConfig
     * @param path
     * @param describe
     * @return
     */
    public static String buildUrl(HostConfig hostConfig,  String path, String describe) {

        if (hostConfig == null) {
            return API_DEFAULT_HOST_URL + path;
        }

        log.info("【{}】exec send sign request... ", describe);

        return hostConfig.useSandboxEnv ? API_TEST_HOST_URL + path : API_DEFAULT_HOST_URL + path;
    }

}
